package com.cn.why.film.filmindex.websocket;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.messaging.simp.SimpMessagingTemplate;
import org.springframework.stereotype.Component;

/**
 * WebSocketTemplate
 */
@Component
public class WebSocketTemplate {
    //websocket消息推送
    @Autowired
    private SimpMessagingTemplate simpMessagingTemplate;
    public WebSocketTemplate(SimpMessagingTemplate simpMessagingTemplate){
        this.simpMessagingTemplate=simpMessagingTemplate;
    }

    //向订阅了 /topic/hello 客户端websocket实例发送数据
    public void sendMessage(String message){
        simpMessagingTemplate.convertAndSend("/topic/hello","hello,client");
    }
}
